<template>
    <div class="menu">
        <Tree :data="menu" show-checkbox></Tree>
    </div>
</template>

<script>
    export default {
        name: "",
        components: {},
        data() {
            return {
                menu: [],
                menuData: []
            }
        },
        methods: {
            getArrayFromList: function (list) {
                let menu = []
                for (let i of list) {
                    let obj = {
                        title: i.menuName,
                        expand: true,
                        checked : true,
                        children: i.sysMenuList
                    }
                    menu.push(obj)
                }
                return menu;
            },

            getMenu: function () {
                this.axios.get(`/login/sysMenu/sysMenuList`)
                    .then((data) => {
                        this.menuData = data.data

                        this.menu = this.getArrayFromList(this.menuData);

                        for (let i of this.menu) {
                            let array = this.getArrayFromList(i.children);
                            i.children = array
                        }
                    })
            }
        },
        mounted() {
            this.getMenu();
        }
    }
</script>

<style scoped>

</style>